// components/GBTEditText/GBTEditText.js
Component({
   options: {
      multipleSlots: true // 在组件定义时的选项中启用多slot支持
   },
   /**
    * 组件的属性列表
    */
   properties: {
      className: String,
      labelCls: String,
      inputCls: String,
      last: {
         type: Boolean,
         value: false
      },
      value: String,
      name: String,
      type: {
         type: String,
         value: 'text'
      },
      password: {
         type: Boolean,
         value: false
      },
      placeholder: String,
      placeholderClass: String,
      placeholderStyle: String,
      disabled: {
         type: Boolean,
         value: false
      },
      maxlength: {
         type: Number,
         value: 140
      },
      focus: {
         type: Boolean,
         value: false
      },
      clear: {
         type: Boolean,
         value: false
      },
      // 是否带清除功能
      syncInput: {
         type: Boolean,
         value: false
      },
      enableNative: {
         type: Boolean,
         value: false
      },
   },

   lifetimes: {
      // 兼容安卓input的输入bug
      onInput: function onInput() {},
      onConfirm: function onConfirm() {},
      onFocus: function onFocus() {},
      onBlur: function onBlur() {},
      onClear: function onClear() {}
   },

   /**
    * 组件的初始数据
    */
   data: {
      _focus: false,
      value: "",
      // placeholderStyle: "color:#ccc",
   },

   /**
    * 组件的方法列表
    */
   methods: {
      onBlur: function onBlur(e) {
         let value = e.detail.value;
         this.setData({
            _focus: false,
            value: value,
         });
         this.triggerEvent("blur", {
            value
         }, {});
      },
      onConfirm: function onConfirm(e) {
         let value = e.detail.value;
         this.setData({
            value: value,
         });
         this.triggerEvent("confirm", {
            value
         }, {});
      },
      onFocus: function onFocus(e) {
         let value = e.detail.value;
         this.setData({
            _focus: true,
            value: value,
         });
         this.triggerEvent("focus", {
            value
         }, {});
      },
      onInput: function onInput(e) {
         let value = e.detail.value;
         this.setData({
            value: value,
         });
         this.triggerEvent("input", {
            value
         }, {});
         console.log(value);
      },
      onClear: function onClear(e) {
         let value = "";
         this.setData({
            value: "",
         });
         this.triggerEvent("clear", {
            value
         }, {});
      }
   }
})